<html>
<head>
<title>article_form</title>
	<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>public/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>public/css/bootstrap-theme.min.css">
	<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>public/css/style.css">
	<script charset="utf-8" src="<?php echo base_url(); ?>public/kindeditor/kindeditor-all-min.js"></script>
	<script charset="utf-8" src="<?php echo base_url(); ?>public/kindeditor/lang/zh-CN.js"></script>
	<script charset="utf-8" src="<?php echo base_url(); ?>public/js/jquery.js"></script>
	<script charset="utf-8" src="<?php echo base_url(); ?>public/js/jquery.upload.js"></script>
</head>
<body>
<?php $this->load->view('admin/header'); ?>
<div class="container from ">
	<div class="page-header">
	<h1><?php echo $title; ?>文章</h1>
	</div>
	<div class="row">
		<div class="col-md-10">
			<form action="" method="post" class="form-horizontal">
				<div class="form-group">
				<label class="col-sm-2 control-label"><b class="error">*</b>标题：</label>
			 		<div class="col-sm-10">
						<input class="form-control" type="text" name="title" value="<?php echo set_value('title',$article->title); ?>" />
						<?php echo form_error('title'); ?>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><b class="error">*</b>文章分类:</label>
					<div class="col-sm-2">
						<select class="form-control" name="catalog_id">
						<option value="" >--</option>
						<?php foreach ($catalogs as  $catalog) {?>
							<option <?php echo  set_select('catalog_id', $catalog->id,$catalog->id==$article->catalog_id); ?> value="<?php echo $catalog->id; ?>"><?php echo $catalog->name; ?></option>
						<?php }?>
						</select>
						<?php echo form_error('catalog_id'); ?>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><b class="error">*</b>简介：</label>
					<div class="col-sm-10">
						<textarea class="form-control" name="desc" rows="2" ><?php echo set_value('desc',$article->desc)?></textarea>
						<?php echo form_error('desc'); ?>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><b class="error">*</b>内容：</label>
					<div class="col-sm-10">
						<textarea class="form-control" id="content" name="content" rows="5" ><?php echo set_value('content',$article->content) ?></textarea>
						<?php echo form_error('content'); ?>
					</div>
				</div>
				<div class="form-group">
					<label  class="col-sm-2 control-label"><b class="error">*</b>图片:</label>
					<div class="col-sm-5">
						<input type="text" id="img"  class="form-control" name="img" <?php echo set_value('img',$article->img)?> />
						<a id="upload" href="#">上传文件</a>
						<?php echo form_error('img'); ?>
					</div>
					<div class="col-sm-5" id="preview"></div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"></label>
					<div class="col-sm-10">
						<input class="btn btn-info"  type="submit" value="确认添加"><a href="<?php echo site_url('/admin/article/index') ?>">返回></a>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<script>
	KindEditor.create('#content');
	$("#upload").click(function(){
		$.upload({
	        url: '<?php echo site_url("admin/util/upload")?>', 
	        fileName: 'file',	 
	        dataType: 'text',
	        onSend: function() {
	            return true;
	        },
	        onComplate: function(data) {
				if(data.indexOf("img")>=0){
				$("#img").val(data);
	        	$("#preview").html('<img style="height:80px;" src="<?php echo base_url()?>'+data+'" />')
				}else{
					alert(data);
				}
	        }
		});
	})

</script>
</body>
</html>